package model

import (
	"time"

	"gorm.io/gorm"
)

// Setting 系统设置模型
type Setting struct {
	ID        uint           `gorm:"primarykey" json:"id"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
	Key       string         `gorm:"size:128;not null;uniqueIndex;comment:设置键" json:"key"`
	Value     string         `gorm:"type:text;comment:设置值" json:"value"`
	Group     string         `gorm:"size:64;default:'default';comment:分组" json:"group"`
	Remark    string         `gorm:"size:255;comment:备注" json:"remark"`
	Type      string         `gorm:"size:32;default:'string';comment:类型" json:"type"` // string,number,boolean,json,array
}

// TableName 设置表名
func (Setting) TableName() string {
	return "go_setting"
}

// SettingSearchParams 系统设置搜索参数
type SettingSearchParams struct {
	Key    string `form:"key" json:"key"`
	Group  string `form:"group" json:"group"`
	Type   string `form:"type" json:"type"`
	Remark string `form:"remark" json:"remark"`
}

// CreateSettingRequest 创建系统设置请求
type CreateSettingRequest struct {
	Key    string `json:"key" binding:"required,max=128"`
	Value  string `json:"value" binding:"required"`
	Group  string `json:"group" binding:"omitempty,max=64"`
	Remark string `json:"remark" binding:"omitempty,max=255"`
	Type   string `json:"type" binding:"omitempty,max=32,oneof=string number boolean json array"`
}

// UpdateSettingRequest 更新系统设置请求
type UpdateSettingRequest struct {
	Value  string `json:"value" binding:"required"`
	Group  string `json:"group" binding:"omitempty,max=64"`
	Remark string `json:"remark" binding:"omitempty,max=255"`
	Type   string `json:"type" binding:"omitempty,max=32,oneof=string number boolean json array"`
}

// BatchUpdateSettingsRequest 批量更新系统设置请求
type BatchUpdateSettingsRequest struct {
	Settings []Setting `json:"settings" binding:"required"`
}
